﻿<UserControl x:Class="SilverlightPacman.PacmanUC"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:lcl="clr-namespace:SilverlightPacman"
    xmlns:controls="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls"

             >
    <Grid x:Name="LayoutRoot">
        <Grid.Resources>
            <lcl:BooleanToVisibilityConverter x:Key="b2v"/>
            <lcl:GhostStateToColorConverter x:Key="GState2Color"/>
            <lcl:GameStatusToVisibilityConverter x:Key="gameStatus2Visibility"/>
            <DataTemplate x:Key="FlyingScoreTemplate">
                <Rectangle Width="20" Height="20" Fill="Red" Canvas.Left="{Binding X}" Canvas.Top="{Binding Y}"/> 
            </DataTemplate>
        </Grid.Resources>
            <Grid>
            <controls:Viewbox x:Name="viewBox" IsTabStop="True" Grid.Column="1" HorizontalAlignment="Stretch" 
                      VerticalAlignment="Stretch" Stretch="Uniform" IsHitTestVisible="True">
                <Canvas Grid.Column="1" Background="Black" Height="620" Width="560">
                    <Canvas.Clip>
                        <RectangleGeometry Rect="0,0,560,620"/>
                    </Canvas.Clip>
                    <Canvas.RenderTransform>
                        <ScaleTransform ScaleX="1" ScaleY="1"/>
                    </Canvas.RenderTransform>
                    <Path x:Name="Wall" Data="{Binding Wall}" Stroke="Gray" StrokeThickness="0" StrokeLineJoin="Round" Opacity="0.7">
                        <Path.Fill>
                            <!--<ImageBrush ImageSource="IMG_0340_800x600.jpg"/>-->
                            <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                                <GradientStop Color="Blue" Offset="0"/>
                                <GradientStop Color="LightBlue" Offset="1"/>
                            </LinearGradientBrush>
                        </Path.Fill>
                    </Path>
                    <Path x:Name="Pills" Fill="White" Data="{Binding Pills}">
                    </Path>
                    <Image x:Name="bonusImage" Source="Images/bonus_1.jpg" Width="20" Height="20"
                            Canvas.Left="{Binding BonusPresenter.CurrentBonus.X}" 
                            Canvas.Top="{Binding BonusPresenter.CurrentBonus.Y}" 
                           Visibility="{Binding BonusPresenter.Visibility}"
                           />
                    <lcl:GhostUC x:Name="ghost1" GhostColor="{Binding GhostPresenter.Ghost.State, 
                                        Converter={StaticResource GState2Color}, ConverterParameter={StaticResource ghostColor1}}"
                                     Canvas.Left="{Binding GhostPresenter.Ghost.X}"
                                     Canvas.Top="{Binding GhostPresenter.Ghost.Y}"
                                     Visibility="{Binding GhostPresenter.Game.Status, Converter={StaticResource gameStatus2Visibility}}"
                                     />
                    <lcl:GhostUC x:Name="ghost2" GhostColor="{Binding GhostPresenter.Ghost.State, 
                                        Converter={StaticResource GState2Color}, ConverterParameter={StaticResource ghostColor2}}" 
                                     Canvas.Left="{Binding GhostPresenter.Ghost.X}"
                                     Canvas.Top="{Binding GhostPresenter.Ghost.Y}"
                                     Visibility="{Binding GhostPresenter.Game.Status, Converter={StaticResource gameStatus2Visibility}}"
                                     />
                    <lcl:GhostUC x:Name="ghost3" GhostColor="{Binding GhostPresenter.Ghost.State, 
                                        Converter={StaticResource GState2Color}, ConverterParameter={StaticResource ghostColor3}}"
                                     Canvas.Left="{Binding GhostPresenter.Ghost.X}"
                                     Canvas.Top="{Binding GhostPresenter.Ghost.Y}"
                                     Visibility="{Binding GhostPresenter.Game.Status, Converter={StaticResource gameStatus2Visibility}}"
                                     />
                    <lcl:GhostUC x:Name="ghost4" GhostColor="{Binding GhostPresenter.Ghost.State, 
                                        Converter={StaticResource GState2Color}, ConverterParameter={StaticResource ghostColor4}}"
                                     Canvas.Left="{Binding GhostPresenter.Ghost.X}"
                                     Canvas.Top="{Binding GhostPresenter.Ghost.Y}"
                                     Visibility="{Binding GhostPresenter.Game.Status, Converter={StaticResource gameStatus2Visibility}}"
                                     />
                    <!--<TextBlock Text="{Binding Ghost1.Ghost.Y}" 
                               Canvas.Left="{Binding Ghost1.Ghost.X}"
                             Canvas.Top="{Binding Ghost1.Ghost.Y}" Foreground="SpringGreen" FontSize="15" />
                    <Ellipse Width="5" Height="5" Fill="Yellow"                 
                             Canvas.Left="{Binding Ghost1.Ghost.X}"
                             Canvas.Top="{Binding Ghost1.Ghost.Y}"
                             />-->

                    <!-- pacman-->
                    <Path x:Name="pacman" Fill="Yellow" Stroke="Red" StrokeLineJoin="Round" 
                      Canvas.Left="{Binding PacmanPresenter.Pacman.X}" 
                      Canvas.Top="{Binding PacmanPresenter.Pacman.Y}" 
                      Visibility="{Binding CurrentGame.Status, Converter={StaticResource gameStatus2Visibility}}">
                        <Path.Data>
                            <PathGeometry>
                                <PathGeometry.Transform>
                                    <TransformGroup>
                                        <RotateTransform Angle="0" CenterX="7.5" CenterY="10" x:Name="orientationPacman"/>
                                        <TranslateTransform X="2" Y="0"/>
                                        <ScaleTransform ScaleX="1" ScaleY="1" />
                                    </TransformGroup>
                                    <!-- 
                                binding doesn't works, on this element
                                <RotateTransform Angle="{Binding PacmanPresenter.Orientation}" CenterX="7.5" CenterY="10" x:Name="rotatePacman"/>
                                    
                                -->
                                </PathGeometry.Transform>
                                <PathFigure IsFilled="True"  IsClosed="True" StartPoint="7.5,10">
                                    <LineSegment x:Name="mouseTopPosition">
                                        <LineSegment.Point>
                                            <Point X="14.5" Y="7" />
                                        </LineSegment.Point>
                                    </LineSegment>
                                    <ArcSegment Size="7,7" IsLargeArc="True" x:Name="mouseBottomPosition" >
                                        <ArcSegment.Point>
                                            <Point X="14.5" Y="13" />
                                        </ArcSegment.Point>
                                    </ArcSegment>
                                </PathFigure>
                            </PathGeometry>
                        </Path.Data>
                    </Path>
                    <!--<TextBlock Text="{Binding PacmanPresenter.Pacman.Y}" 
                      Canvas.Left="{Binding PacmanPresenter.Pacman.X}" 
                      Canvas.Top="{Binding PacmanPresenter.Pacman.Y}" 
                        Foreground="SpringGreen" FontSize="15" />-->

                    <lcl:FlyingScoreUC Height="620" Width="560"/>
                </Canvas>
            </controls:Viewbox>
        </Grid>

        <MediaElement x:Name="mediaelem" AutoPlay="False"  IsMuted="{Binding IsMuted}"/>

    </Grid>
</UserControl>
